import unittest
from .. import MahJong, Commondef, Rule


class MyTestCase(unittest.TestCase):
    def test_majiangTileEq(self):
        # arrange

                # act
        Tile1 = MahJong.MahJongTile(1, 2)
        Tile2 = MahJong.MahJongTile(1, 2)
        # assert
        self.assertEqual(Tile1, Tile2)

    def test_majiangTileEqRelate(self):
        # arrange

                # act
        tile1 = MahJong.MahJongTile(1, 2)
        tile2 = MahJong.MahJongTile(1, 2)
        tile3 = MahJong.MahJongTile(1, 3)
        tile3 = MahJong.MahJongTile(Commondef.Kind.East)

        # assert
        self.assertIs(True, tile1 >= tile2)
        self.assertIs(True, tile1 <= tile2)
        self.assertEqual(True, tile3 > tile2)
        self.assertEqual(False, tile3 == tile2)
        self.assertEqual(True, tile3 > tile1)

    def test_majiangTileNe(self):
        # arrange
        Tile1 = MahJong.MahJongTile(1, 3)
        Tile2 = MahJong.MahJongTile(1, 2)
        # act
        isNotEq = Tile1 != Tile2
        # assert
        self.assertIs(True, isNotEq)

    def test_CreatADeckCreate(self):
        # arrange
        mjCreater = MahJong.MahJongCreater()
        suit = mjCreater.CreateKindGroup(Commondef.KindGroup.Suits)
        flowers = mjCreater.CreateKindGroup(Commondef.KindGroup.Flowers)
        honors = mjCreater.CreateKindGroup(Commondef.KindGroup.Honor)

        baseTiles = mjCreater.CreateMahJongByRule(Commondef.TilesType.Base)
        # act
        suitCount = len(suit)
        flowersCount = len(flowers)
        honorsCount = len(honors)
        countAll = suitCount + flowersCount + honorsCount

        baseTilesCount = len(baseTiles)
        # assert
        self.assertEqual(3 * 4 * 9, suitCount)
        self.assertEqual(8, flowersCount)
        self.assertEqual(7 * 4, honorsCount)
        self.assertEqual(countAll, 144)

        self.assertEqual(3 * 4 * 9, baseTilesCount)

    def test_CreatMahJong(self):
        # arrange
        mj = MahJong(Rule.testRule)
        mj2 = MahJong(Rule.testRule)
        # act
        firstLeftCount = len(mj.tiles)
        # assert
        mj.Shuffle()
        mj2.Shuffle()
        print(mj.tiles)
        for index in xrange(1, firstLeftCount + 1):
            tile = mj.Deal()[0]
            print(tile.type, tile.rank)
            # print(tile2.type,tile2.rank)
            # print(">>>>>>>>>>>>")
        # mj.tiles.sort()

    def test_CreatPlayFlow(self):

        pass
        # rule = CreatRule()
        # majiang = MahJong(rule)
        # gameManager = GameManager(rule)
        # player1 = getPlayer()
        # player2 = getPlayer()
        # gameManager.JoinPlayer(player1)
        # gameManager.JoinPlayer(player2)
        # bMeet = gameManager.IsMeetStart()
        # if bMeet:
        # 	gameManager.startGame()
        #    	gameManager.startRound()
        #        	gameManager.majiang = majiang
        #        	gameManager.suffle()
        #        	gameManager.PreSet()
        #        	gameManager.AutoRun()
        #        	gameManager.endRound()
        #        	gameManager.Score()
        #    gameManager.endGame()


if __name__ == '__main__':
    unittest.main()
